package com.srd.phone.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.shengrongdai.srd.R;

/**
 * 主界面  标的列表
 */
public class TabTenderListFragment extends BaseFragment implements View.OnClickListener {

    private View viewRoot;
    private RadioGroup rg_retrieve;

    private TabTenderListLicaiFragment fragment1;
    private TabTenderListZhaiquanFragment fragment2;

    private LinearLayout ll_tender_lc;
    private LinearLayout ll_tender_zq;

    private boolean isLoading = false;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (viewRoot == null) {
            viewRoot = inflater.inflate(R.layout.fragment_tab_tender_list, container, false);
            ImageView iv_back = (ImageView) viewRoot.findViewById(R.id.iv_common_back);
            iv_back.setVisibility(View.GONE);
            TextView tv_common_title = (TextView) viewRoot.findViewById(R.id.tv_common_title);
            tv_common_title.setText("投资");
        }
        return viewRoot;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isLoading == false && isVisibleToUser == true) {
            isLoading = true;
            initView();
        }
    }

    public void initView() {
        fragment1 = new TabTenderListLicaiFragment();
        fragment2 = new TabTenderListZhaiquanFragment();
        ll_tender_lc = (LinearLayout) viewRoot.findViewById(R.id.ll_tender_lc);
        replaceFragment(R.id.ll_tender_lc, fragment1);
        ll_tender_zq = (LinearLayout) viewRoot.findViewById(R.id.ll_tender_zq);
        replaceFragment(R.id.ll_tender_zq, fragment2);
        rg_retrieve = (RadioGroup) viewRoot.findViewById(R.id.rg_retrieve);
        rg_retrieve.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.rb_touzi) {
                    ll_tender_lc.setVisibility(View.VISIBLE);
                    ll_tender_zq.setVisibility(View.GONE);
                } else if (checkedId == R.id.rb_zhaiquan) {
                    ll_tender_lc.setVisibility(View.GONE);
                    ll_tender_zq.setVisibility(View.VISIBLE);
                }
            }
        });
        rg_retrieve.check(R.id.rb_touzi);
    }

    @Override
    public void onClick(View v) {

    }
}
